<?php
#### VALIDATION  ###############################################################
class Validation {

	var $feedback;

	#### LENGTH ################################################################
	function length($string, $min_length, $max_length) {

		if (strlen($string) < $min_length) {
			$this->feedback .= 'A minimum of '.$min_length.' characters is required';
			return TRUE;
		}
		else if (strlen($string) > $max_length) {
			$this->feedback .= 'A maximum of '.$max_length.' characters is required';
			return TRUE;
		}
		else return FALSE;

	}

	#### ALPHA #################################################################
	function alpha($alpha, $min_length = FALSE, $max_length = FALSE) {

		// Check length if needed
		if ($min_length || $max_length) if($this->length($alpha, $min_length, $max_length)) return TRUE;

		// Should contain no numeric characters
		if(ereg('[^a-zA-Z._-]', $alpha)) {
			$this->feedback .= 'A minimum of '.$min_length.' characters is required';
			return TRUE;
		}
		else return FALSE;
	}

	#### NUMERIC ###############################################################
	function numeric($numeric, $min_length = FALSE, $max_length = FALSE) {

		// Check length if needed
		if ($min_length || $max_length) if($this->length($numeric, $min_length, $max_length)) return TRUE;

		// Should only contain numeric characters
		if (!is_numeric($numeric)) {
			$this->feedback .= 'A minimum of '.$min_length.' characters is required';
			return TRUE;
		}
		else return FALSE;
	}

	#### ALPHANUMERIC ##########################################################
	function alphanumeric($alphanumeric, $min_length = FALSE, $max_length = FALSE) {

		// Check existence
		if ($alphanumeric == '') return TRUE;

		// Check length if needed
		if ($min_length || $max_length) if($this->length($alphanumeric, $min_length, $max_length)) return TRUE;
	}

	#### URL ###################################################################
	function url($url) {

		// Check existence
		if ($url == '') return TRUE;

		if (eregi('^(http|ftp)://(www\.)?.+\.(com|net|org)$', $url)) return TRUE;
		else return FALSE;
	}

	#### EMAIL #################################################################
	function email($email, $blacklist_check = FALSE) {
		global $config;

		// Simply black list checking, feel free to add your own!
		if ($blacklist_check) {

			$blacklist[] = 'ipoo.org';
			$blacklist[] = 'h8s.org';
			$blacklist[] = 'hatespam.org';
			$blacklist[] = 'oopi.org';
			$blacklist[] = 'poofy.org';

			foreach ($blacklist as $domain) {
				if (strstr($email, $domain)) return FALSE;
			}
		}

		/*if ($common['email_check_type'] == 2) {
			$email_part = explode('@', $email);
			$user = $email_part[0];
			$host = $email_part[1];
			$fp = fsockopen ($host, 25);
			set_socket_blocking ($fp, TRUE);
			fputs ($fp, "Hello Local\n");
			fgets ($fp, 2000);
			fgets ($fp, 2000);
			fputs ($fp, "Mail From:<".$user."@".$host."> \n");
			fgets ($fp, 2000);
			fputs ($fp, "RCPT to:aetos<".$user."@".host."> \n");
			$result = fgets($fp, 2000);
			$st = substr($result, 0, 3);
			if ($st == 250) return TRUE;
			else return FALSE;
		}*/

		if (eregi('^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$', $email)) return TRUE;
		else return FALSE;
	}

	#### GETFEEDBACK ########################################################
	function getFeedback() {
		return $this->feedback;
	}
}
?>